
/*

Author   : chaos

FileName : dyna_binding.cpp

Date     : 15/08/17 11:30:04

*/
#include <iostream>
#include <cstring>
using namespace std;

class person;
class object
{
    protected:
        char color[10];
        char type[10];

    public:
        object(char * o_type ,char * o_color)
        {
            strcpy(type,o_type);
            strcpy(color,o_color);
        }

        object(){}
        virtual void set_object(person & a_person)
        {
            cout << "The set_object(person & a_person)"
                << "of object is called !" << endl;
        }
};

class clothes;
class pants;
class shoe;

class person
{
    protected:
        char last_name[5];
        char first_name[15];
        clothes * my_clothes;
        shoe * my_shoe;
        pants * my_pants;
        friend class clothes;
        friend class shoe;
        friend class pants;

    public:
        person(const char * l_name ,const char * f_name)
        {
            strcpy(last_name,l_name);
            strcpy(first_name,f_name);
        }

        void wear(object & object)
        {
            cout << "The wear(object & object) of person is called ." << endl;
            cout << endl;
            object.set_object(*this);
        }


        void show_data();
};

class shoe:public object
{
    private:
        friend class person;

    public:
        shoe(char * type,char * color):object(type,color){}
        void set_object(person & a_person)
        {
            cout << "The set_object() of shoe is called!";
            cout << endl << endl;

            a_person.my_shoe = this;
        }
};

class clothes:public object
{
    private:
        friend class person;

    public:
        clothes(char * type,char * color ):object(type,color){}
    void set_object(person & a_person)
    {
        cout << "The set_object() of clothes is called!";
        cout << endl << endl;
        a_person.my_clothes = this;
    }
};

class pants:public object
{
    private:
        friend class person;

    public:
        pants(char * type,char * color):object(type,color){}

        void set_object(person & a_person)
        {
            cout << "The set_object() of pants is called !";
            cout << endl << endl;
        }
};

void person::show_data()
{
    cout << endl << "My name is " << first_name
        << " " << last_name << " . " << endl;
    cout << "I wear" << my_clothes->color << " " <<  my_clothes->type;
    cout << " ," << my_pants->color << " " << my_pants->type;
    cout << " and " << my_shoe->color << " " << my_shoe->type << "." << endl;
}
int main(int argc ,char *argv[])
{
    person John("John","Kuo");
    object a_object;
    clothes a_clothes("T shirt","white");
    pants a_pants("short","green");
    shoe a_shoe("gymshoe","blue");

    cout << "The first testing ......." << endl;
    John.wear(a_object);
    cout << "The second testing ......." << endl;
    John.wear(a_clothes);
    John.wear(a_pants);
    John.wear(a_shoe);

    John.show_data();

    return 0;
}
